/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package course.ya.doc.from.code.model.statements;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Transient;

/**
 *
 * @author Denis
 */
@Entity
@DiscriminatorValue("CommentStatement")
public class CommentStatement extends AStatement {

    @Column(name = "comment")
    private String commentary;
    @Transient
    private Pattern pattern;
    @Transient
    private Matcher matcher;
    @Transient
    private static final String STRING_PATTERN = "//(.*)";

    public CommentStatement() {
    }

    public CommentStatement(String str) {
        this.pattern = Pattern.compile(STRING_PATTERN);
        this.commentary = findStr(str);
    }

    public String findStr(String input) {
        matcher = pattern.matcher(input);
        if (matcher.find()) {
            return matcher.group(1);
        } else {
            return null;
        }
    }

    @Override
    public String toString() {
        return commentary;
    }
}
